#ifndef ACCELMANAGER_H
#define ACCELMANAGER_H

#include <QThread>
#include <QtGlobal>
#include <QtGui>
#include <stdio.h>
#include <time.h>
#include <sys/times.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <assert.h>

typedef struct {
	struct timeval time;
	uint16_t type;
	uint16_t code;
	int32_t value;
} Event;

//http://wiki.openmoko.org/wiki/Accelerometer_data_retrieval
class AccelManager : public QThread
{
	Q_OBJECT
	
	public:
		enum State {UP, DOWN, UNKNOWN};
		AccelManager();
        ~AccelManager();
		void run();
		void stop();
		int getCurrentState();

	private:
		QFile *accelerometer;
		bool activated;
		int currentState;
		int indicator;
		int threshold;

		bool updateState();
		
	signals:
		void stateChangeSignal(int state);

	private slots:
		int readEvent(char *buffer);
		void stateChangeListener(int state);
};

#endif

